package com.qtz.demo.controller;

import com.qtz.demo.bean.Result;
import com.qtz.demo.bean.User;
import com.qtz.demo.service.UserServiceImpl;
import javafx.scene.chart.ValueAxis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")

public class UserController {

    @Autowired
    private UserServiceImpl userService;

    //用户登录
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public Result<User> login(@RequestBody Map<String,String> map){
        User user=new User();
        user.setUsername(map.get("username"));
        user.setUserpwd(map.get("userpwd"));
        User list = userService.login(user);
        Result result = new Result();
        if (list!=null){
            result.setCode(0);
            result.setMsg("成功");
            result.setData(list);
        }else{
            result.setCode(-1);
            result.setMsg("失败");
            result.setData("");
        }
        return result;
    }

    //添加用户
    @RequestMapping(value = "/addUser",method =RequestMethod.POST)
    @ResponseBody
    public boolean addUser(@RequestBody Map<String,String> map){
        User user = new User();

        user.setUsername(map.get("username"));
        user.setUserpwd(map.get("userpwd"));
        user.setPhone(map.get("phone"));
        user.setEmail(map.get("email"));

        if(userService.addUser(user)){
            return true;
        }
        else {
            return false;
        }

    }

    //显示未审核用户
    @RequestMapping(value = "/showUnchecked",method = RequestMethod.GET)
    @ResponseBody
    public List<User> showUnchecked(){
        return userService.showUnchecked();
    }

    //审核通过
    @RequestMapping(value = "/check/{uid}",method = RequestMethod.GET)
    @ResponseBody
    public boolean check(@PathVariable("uid") String uid){
        return userService.check(uid);
    }
}
